package com.letv.android.client.episode.parser;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import com.letv.core.bean.VideoBean;
import com.letv.core.parser.LetvMasterParser;
import com.letv.core.utils.LogInfo;

public class VideoParser extends LetvMasterParser<VideoBean> {

	@Override
	public VideoBean parse(JSONObject data) throws Exception {

		if (data != null) {
			VideoBean videoPlayerLibs = new VideoBean();

			try {
				videoPlayerLibs.setVid(getLong(data, "vid"));
				videoPlayerLibs.setNameCn(getString(data, "nameCn"));
				videoPlayerLibs.setSubTitle(getString(data, "subTitle"));
				videoPlayerLibs.setSinger(getString(data, "singer"));
				videoPlayerLibs.setReleaseDate(getString(data, "releaseDate"));
				videoPlayerLibs.setStyle(getString(data, "style"));
				videoPlayerLibs.setGuest(getString(data, "guest"));
				videoPlayerLibs.setBtime(getLong(data, "btime"));
				videoPlayerLibs.setEtime(getLong(data, "etime"));
				videoPlayerLibs.setCid(getInt(data, "cid"));
				videoPlayerLibs.setPid(getLong(data, "pid"));
				videoPlayerLibs.setType(getInt(data, "type"));
				videoPlayerLibs.setPlayCount(getLong(data, "playCount"));
				videoPlayerLibs.setAt(getInt(data, "at"));
				videoPlayerLibs.setDuration(getLong(data, "duration"));
				videoPlayerLibs.setPlay(getInt(data, "play"));
				videoPlayerLibs.setJump(getInt(data, "jump"));
				videoPlayerLibs.setJumpLink(getString(data, "jumplink"));
				videoPlayerLibs.setPay(getInt(data, "pay"));
				videoPlayerLibs.setDownload(getInt(data, "download"));
				videoPlayerLibs.setControlAreas(getString(data, "controlAreas"));
				videoPlayerLibs.setDisableType(getInt(data, "disableType"));
				videoPlayerLibs.setMid(getString(data, "mid"));
				videoPlayerLibs.setBrList(getString(data, "brList"));
				videoPlayerLibs.setEpisode(getString(data, "episode"));	
				videoPlayerLibs.setSinger(getString(data,"singer"));
				videoPlayerLibs.setCreateYear(getString(data,"createYear"));
				videoPlayerLibs.setCreateMonth(getString(data,"createMonth"));
				videoPlayerLibs.setVideoTypeKey(getString(data,"videoTypeKey"));
                videoPlayerLibs.setControlAreas(getString(data,"controlAreas"));
                videoPlayerLibs.setVideoType(getString(data,"videoType"));
                videoPlayerLibs.setPorder(getString(data,"porder"));

				JSONObject picAll = getJSONObject(data, "picAll");
				if (picAll != null) {
					if(has(picAll,"320*200")){
	                    videoPlayerLibs.setPic320(getString(picAll,"320*200"));
	                }
					if (has(picAll, "200*150")) {
						videoPlayerLibs.setPic300(getString(picAll, "200*150"));
					} 
					if (has(picAll, "120*90")) {
						videoPlayerLibs.setPic(getString(picAll, "120*90"));
					}
				}
                

                JSONArray jsonFocusrray = null;
                ArrayList<VideoBean.WatchingFocusItem> watchFocusList = null;
                jsonFocusrray = getJSONArray(data, "watchingFocus");
                if(jsonFocusrray !=null && jsonFocusrray.length() >0){
                    watchFocusList = new ArrayList<VideoBean.WatchingFocusItem>();
                    VideoBean.WatchingFocusItem mWatchingFocusItem = null;
                    JSONObject jsonFocusObj = null;
                    int len = jsonFocusrray.length();
                    for (int i=0; i<len; i++){
                        jsonFocusObj = getJSONObject(jsonFocusrray, i);
                        mWatchingFocusItem = new VideoBean.WatchingFocusItem();
                        mWatchingFocusItem.setDesc(jsonFocusObj.getString("desc"));
                        mWatchingFocusItem.setId(jsonFocusObj.getInt("id"));
                        mWatchingFocusItem.setPicUrl(jsonFocusObj.getString("pic"));
                        mWatchingFocusItem.setTimeDot(jsonFocusObj.getString("time"));
                        watchFocusList.add(mWatchingFocusItem);
                    }
                    if(watchFocusList != null && watchFocusList.size() >0){
                        videoPlayerLibs.setWatchingFocusList(watchFocusList);
                    }
                }
                
                /*
                 * 相关中猜你喜欢recData数据拓展 
                 */
                videoPlayerLibs.setTitle(getString(data,"title"));
                videoPlayerLibs.setPidname(getString(data,"pidname"));
                videoPlayerLibs.setSubname(getString(data,"subname"));
                videoPlayerLibs.setPicHT(getString(data,"picHT"));
                videoPlayerLibs.setPicST(getString(data,"picST"));
                videoPlayerLibs.setPic320_200(getString(data,"pic320*200"));
                videoPlayerLibs.setNowEpisodes(getString(data,"nowEpisodes"));
                videoPlayerLibs.setDirector(getString(data,"director"));
                videoPlayerLibs.setStarring(getString(data,"starring"));
                videoPlayerLibs.setScore(getString(data,"score"));
                videoPlayerLibs.setReid(getString(data,"reid"));
                videoPlayerLibs.setBucket(getString(data,"bucket"));
                videoPlayerLibs.setArea(getString(data,"area"));
                videoPlayerLibs.setCornerMark(getString(data,"cornerMark"));
                
			} catch (Exception e) {
                LogInfo.log("king","Exception is " + e.toString());
				e.printStackTrace();
			}

			return videoPlayerLibs;
		}

		return null;
	}

}
